

package com.maoshi.shop.user.api.listener;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.maoshi.shop.bean.app.dto.ShopCartOrderMergerDto;
import com.maoshi.shop.bean.enums.ScoreLogType;
import com.maoshi.shop.bean.event.LevelUpEvent;
import com.maoshi.shop.bean.event.SubmitScoreOrderEvent;
import com.maoshi.shop.bean.model.UserExtension;
import com.maoshi.shop.bean.order.SubmitOrderOrder;
import com.maoshi.shop.common.exception.MaoshiShopBindException;
import com.maoshi.shop.security.api.util.SecurityUtils;
import com.maoshi.shop.service.UserExtensionService;
import com.maoshi.shop.user.comment.model.UserLevel;
import com.maoshi.shop.user.comment.model.UserScoreLog;
import com.maoshi.shop.user.comment.service.UserLevelService;
import com.maoshi.shop.user.comment.service.UserScoreLogService;
import lombok.AllArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 用户等级提升操作
 *
 * @author lhd
 */
@Component("levelUpListener")
@AllArgsConstructor
public class LevelUpListener {

    private final UserLevelService userLevelService;
    private final UserExtensionService userExtensionService;

    /**
     * 用户等级提升操作
     */
    @EventListener(LevelUpEvent.class)
    public void levelUpListener(LevelUpEvent event) {
        UserLevel userLevel = userLevelService.getOne(
                new LambdaQueryWrapper<UserLevel>().eq(UserLevel::getLevel, 1).eq(UserLevel::getLevelType, 0));
        ArrayList<UserLevel> userLevels = new ArrayList<>();
        userLevels.add(userLevel);
        UserExtension userExtension = userExtensionService.getOne(new LambdaQueryWrapper<UserExtension>().eq(UserExtension::getUserId, event.getUserId()));
        userLevelService.levelUp(userLevels,null,userExtension,null);
    }

}
